<template>
  <c-form-dialog
    ref="form"
    :visible.sync="innerVisible"
    :form-items="formItems"
    :form-data="formData"
    :table-name="tableName"
    :table-id="tableId"
    @close="handleClose"
    @success="handleSuccess"
    :before-save="handleBeforeSave"
  ></c-form-dialog>
</template>

<script>
import { mapGetters } from 'vuex'
import { enumLevelClassType } from '@/credit/views/city/self/after/enum'
import { dateFormat } from '@/common/utils/common'
export default {
  components: {},
  props: {
    visible: Boolean,
    tableId: String,
    queryId: String,
    formData: {
      type: Object,
      default() {
        return {}
      },
    },
  },
  data() {
    return {
      innerVisible: false,
      tableName: 'five_level_class',
      formItems: [
        {
          tag: 'select',
          itemAttrs: {
            label: '五级分类',
            rules: [{ required: true, message: '请选择五级分类', trigger: 'change' }],
          },
          attrs: {
            key: 'class_type',
            options: enumLevelClassType,
            placeholder: '请选择五级分类',
          },
        },
        {
          tag: 'textarea',
          itemAttrs: { label: '备注' },
          attrs: { key: 'remark', value: '', placeholder: '请输入备注', autosize: { minRows: 3 } },
        },
      ],
    }
  },
  computed: {
    ...mapGetters(['user', 'clientId']),
  },
  watch: {
    visible(val) {
      this.innerVisible = val
    },
  },
  created() {},
  mounted() {},
  methods: {
    handleBeforeSave(model) {
      model.evaluate_date = dateFormat(new Date())
      model.submit_person_name = this.user.realName
      model.customer_related_id = this.queryId
      return model
    },
    handleClose() {
      this.$emit('update:visible', false)
    },
    handleSuccess(res) {
      this.$emit('success', res)
    },
  },
}
</script>
<style lang="scss" scoped></style>
